﻿#ifndef WIDGETCOMCLIENT_H
#define WIDGETCOMCLIENT_H

#include <QWidget>
#include <QGroupBox>
#include <QLineEdit>
#include <QTextEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QSpinBox>
#include <QComboBox>
#include <QHBoxLayout>
#include "ComBase.h"

class WidgetComClient : public QGroupBox
{
    Q_OBJECT
public:
    explicit WidgetComClient(const QString& name = "", QWidget *parent = nullptr);

    void addComClient(ComBase* client);

signals:
    void sigConfigChanged(const ComClientConfig& config);
    void sigAddOne(const ComClientConfig& config);
    void sigDeleteOne(const QString& name);
    void sigWriteData(const QString& txt);
private:
    void setupUI();
    void setupConfigUI();
    void setupSendRev();
    void initConnection();

    ComClientConfig getConfig();

    void onSaveConfig();

    void onComSelectChanged(const int& index);
private:
    QMap<QString, ComBase*> mMapComClient;

    //control
    QHBoxLayout* mLayout;
    //PLC配置控件
    QPushButton* pbtnAddOne;
    QPushButton* pbtnDeleteOne;
    QPushButton* pbtnApplyPLC;
    QComboBox* cbboxComNameList;
    QComboBox* cbboxComTypeList;

    //串口
    QWidget* wgtSerialConfig;
    QComboBox* cbboxSerialList;
    QComboBox* cbboxSerialBaudRate;
    QComboBox* cbboxSerialDataBits;
    QComboBox* cbboxSerialParity;
    QComboBox* cbboxSerialStopBits;
    QComboBox* cbboxSerialFlowControl;
    //socket
    QWidget* wgtSocketConfig;
    QLineEdit* ledtOpponentIP;
    QSpinBox* spboxOpponentPort;
    QLineEdit* ledtLocalIP;
    QSpinBox* spboxLocalPort;
    //udp
    QWidget* wgtSendType;
    QComboBox* cbboxUdpSendType;

    QCheckBox* chkboxSendHex;

    //接收区
    QCheckBox* chkboxIsDisplayData;
    QCheckBox* chkboxIsDisplayHex;
    QPushButton* pbtnClear;
    QTextEdit* txtedtDataRev;

    //发送区
    QTextEdit* txtedtDataSend;
    QPushButton* pbtnSendData;

};

#endif // WIDGETCOMCLIENT_H
